`:top
In `F33f`_`[computer programming`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Computer_programming]`_`f, `!autoloading`! is the capability of loading and `F33f`_`[linking`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Linker_(computing)]`_`f portions of a program from `F33f`_`[mass storage`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Mass_storage]`_`f automatically when needed, so that the programmer is not required to define or include those portions of the program explicitly. Many high-level programming languages include autoload capabilities, which sacrifice some `F33f`_`[run-time`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Run_time_(program_lifecycle_phase)]`_`f speed for ease of coding and speed of initial compilation/linking.
Typical autoload systems intercept `F33f`_`[procedure calls`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Procedure_call]`_`f to undefined `F33f`_`[subroutines`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Subroutine]`_`f. The autoloader searches through a `F33f`_`[path`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Path_(computing)]`_`f of directories in the computer's `F33f`_`[file system`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=File_system]`_`f, to find a file containing `F33f`_`[source`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Source_code]`_`f or `F33f`_`[object`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object_code]`_`f code that defines the subroutine. The autoloader then loads and links the file, and hands control back to the main program so that the subroutine gets executed as if it had already been defined and linked before the call.
Many interactive and high-level languages operate in this way. For example, `F33f`_`[IDL`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=IDL_(programming_language)]`_`f includes a primitive path searcher, and `F33f`_`[Perl`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Perl]`_`f allows individual `F33f`_`[modules`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Perl_module]`_`f to determine how and whether autoloading should occur. The `F33f`_`[Unix shell`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Unix_shell]`_`f may be said to consist almost entirely of an autoloader, as its main job is to search a path of directories to load and execute command files. In `F33f`_`[PHP`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=PHP]`_`f 5, autoload functionality is triggered when referencing an undefined `F33f`_`[class`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Class_(computer_programming)]`_`f. One or more autoload functions—implemented as the `B100`F9d9__autoload`f`b magic function or any function registered to the `F33f`_`[SPL`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Standard_PHP_Library]`_`f autoload stack—is called and given the opportunity to define the class, usually by loading the file it is defined in.
>>Contents
• `F0af`_`[PHP`#php]`_`f
• `F0af`_`[External links`#external-links]`_`f
-─
>>PHP
`B100`F9d9spl_autoload_register(function ($class) {`f`b
`B100`F9d9 $file = 'src/' . str_replace('\\\\', '/', $relative_class) . '.php';`f`b
`B100`F9d9 if (file_exists($file)) {`f`b
`B100`F9d9 require $file;`f`b
`B100`F9d9 }`f`b
`B100`F9d9});`f`b
>>External links
• PSR-4 Improved Autoloading Standard
• Autoloading Classes in PHP
• spl_autoload_register in PHP
`c`F0af`_`[↑ Back to top`#top]`_`f`a